package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Order;
import cn.wolfcode.trip.base.domain.OrderItem;
import cn.wolfcode.trip.base.service.IOrderService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping("/user")
    public JsonResult listOrder(Long userId){
        JsonResult jsonResult = new JsonResult();
        //根据用户的id查询他所有的订单
        List<Order> orders = orderService.getCurrentAllOrder(userId);
        //遍历他所有的订单
        Object[] list = new Object[orders.size()];
        for (int i = 0; i < orders.size(); i++) {
            List<OrderItem> OrderItems = orderService.getCurrentAllOrderItem(orders.get(i).getId());
            list[i]=OrderItems;
        }

        return jsonResult.setResult(list);
    }

//    @GetMapping
//    public JsonResult listByStatuss(Long userId,Integer status){
//        JsonResult jsonResult = new JsonResult();
//        List<Order> orders = orderService.getStatusOrder(userId,status);
//        for (Order order : orders) {
//            List<OrderItem> orderItems = orderService.getCurrentAllOrderItem(order.getId());
//            return jsonResult.setResult(orderItems);
//        }
//        return jsonResult.mark("");
//    }
    @GetMapping("listByStatus")
    public List<Map> listByStatus(Long userId,Integer status){

        List<Map> statusOrders = orderService.getStatusOrders(userId, status);
        return statusOrders;
    }
}
